package com.test.rxjavademo;


import org.jetbrains.annotations.NotNull;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

class MapDemo {

    public static void main(String[] args) {
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                List<Student> students = StudyModel.getStudents();
//                for(Student student:students){
//                    List<Student.Course> courseList = student.getCourseList();
//                    for(Student.Course course:courseList){
//                        System.out.println("");
//                        System.out.println(student);
//                        System.out.println(course);
//                    }
//                }
//            }
//        }).start();


//        Observable.fromIterable(StudyModel.getStudents())
//                .map(new Function<Student, List<Student.Course>>() {
//                    @NotNull
//                    @Override
//                    public List<Student.Course> apply(@NotNull Student student) throws Exception {
//                        return null;
//                    }
//                }).subscribe(new Consumer<List<Student.Course>>() {
//            @Override
//            public void accept(@NotNull List<Student.Course> courses) throws Exception {
//                    for(Student.Course course:courses){
//                        System.out.println("");
//                        System.out.println(course);
//                    }
//            }
//        });


        Observable.fromIterable(StudyModel.getStudents())
                .flatMap(new Function<Student, ObservableSource<?>>() {
                    @NotNull
                    @Override
                    public ObservableSource<?> apply(@NotNull Student student) throws Exception {
                        System.out.println("");
                        System.out.println(student);
                        return Observable.fromIterable(student.getCourseList());
                    }
                }).subscribe(new Consumer<Object>() {
            @Override
            public void accept(@NotNull Object o) throws Exception {
                System.out.println(o);
            }
        });




    }
}
